<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto;border:1px solid #eee}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto;border:1px solid #eee}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>

<body style='position:relative'>

	<div id='verify_area' style='display:none;position:fixed;border:1px solid;width:100%;height:100%'>
		<div style='width:400px;margin:100px auto;background:#eef;padding:30px 0'>
			<h3 style='text-align:center;font-size:15px'>请输入<span id='join_area_name'></span>小区准入口令</h3>
			<div style='width:250px;margin:0 auto'>
				口　令：
				<input type="text" id='verify_pwd' />
			</div>
			<div style='margin:20px auto;text-align:center'>
				<button id='verify_submit'>加入小区</button>
				<button id='verify_back'>返回</button>
			</div>
		</div>
	</div>



	<div id='content'>
		<div style='padding:5px 5px 0 5px;font-size:12px;text-align:right'>
			<span onclick='location.replace("index.html")'>切换城市</span>　
			<span onclick='location.href="me.html"'>我的小区</span>
		</div>


		<div style='text-align:center'>
		

			<h2>小区列表</h2>
			
			<div style='font-size:12px;margin-bottom:20px'>当前城市：<span id='current_county'></span></div>


			<!--列表-->
			<div style='padding:20px 0;border:0px solid' id='areaList'></div>

			<div id='fpage' style='margin:30px 0;text-align:center'></div>
		</div>

	</div>
</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
if(!sessionStorage.area_list_pnow){
	sessionStorage.area_list_pnow = 1;
}
var tokenSet = GetCityInfo();
var user_info = GetUserInfo();

var user_info;
var current_area_id;
var current_area_pwd;
var current_area_name;




$(function(){
	$('#current_county').text(tokenSet[1]);
	//获取当前城市的小区列表
	GetCityAreaList();
	

	//加入小区
	$('#verify_submit').click(function(){
		var pwd = $('#verify_pwd').val().trim();
		if(!current_area_id || !current_area_pwd || !pwd){
			return;
		}
		C(current_area_pwd);
		if(pwd != current_area_pwd){
			A('准入码不正确！');return;
		}
		var data = {
			type:'join_area',
			area_id:current_area_id,
			pwd:pwd
		}
		AjaxBefore(data,function(res){
			C(res);
			if(!/^{.*}$/.test(res)){
				return;
			}
			var tmp = JSON.parse(res);
			sessionStorage.token1 = tmp.token1;
			switch(tmp.stat){
				case 'err1':A('缺少参数!');break;
				case 'err2':A('密码不正确!');break;
				case 'err3':
					//用户已存在小区内,需刷新页面缓存
					break;
				case 'err4':A('加入小区失败!');break;
				case 'ok':
					//刷新我的小区缓存
					var s1 = 'localStorage.MyAreaList_'+tokenSet[0] + '=""';
					eval(s1);

					A('加入小区成功！!');
					//location.reload();
					jump_area_detail(current_area_id,current_area_name);
					break;
			}
		});
	});

	//密码验证框隐藏
	$('#verify_back').click(function(){
		$('#verify_area').hide();
	});
});

//获取当前城市的小区列表
function GetCityAreaList(){
	AjaxBefore({type:'GetCityAreaList',pnow:sessionStorage.area_list_pnow},function(res){
		C('GetCityAreaList from after');
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		PareData(tmp.data.data,tokenSet[0]);
	});
}

//解析当前城市列表数据
function PareData(list,city_code){
	var str = '';
	if(typeof(list) == 'object' && list.length > 0){
		for(var i=0;i<list.length;i++){
			//str += "<div style='margin:10px 0' onclick=jump_area_detail("+list[i].id+",'" + list[i].area_name + "')>" + list[i].area_name + "</div>";
			str += "<div style='margin:10px 0' onclick=view_pwd_area("+list[i].id+","+list[i].pwd+",'"+list[i].area_name+"')>" + list[i].area_name + "</div>";
		}
		var max_page = parseInt(sessionStorage.area_list_pnow)+1;
	}else{
		var max_page = parseInt(sessionStorage.area_list_pnow);
	}
	$('#areaList').html(str);
	Fpage(parseInt(sessionStorage.area_list_pnow),max_page,function(p){
		sessionStorage.area_list_pnow = p;
			GetCityAreaList(tokenSet[0]);
	},1,1,'#fpage');

}

//非小区用户，点击小区时弹出验证框
function view_pwd_area(area_id,pwd,area_name){
	GetMyAreaList(tokenSet[0],function(my_area_list){
		C(my_area_list);
		if(my_area_list && my_area_list.area_id_list){
			var l2 = my_area_list.area_id_list.split(',');
			for(var i=0;i<l2.length;i++){
				if(area_id == l2[i]){
					jump_area_detail(area_id,area_name);
					return;
				}
			}
		}
		$('#verify_area').show();
		current_area_id = area_id;
		current_area_pwd = pwd;
		current_area_name = area_name;
		$('#join_area_name').text(area_name);
	});

}


</script>